#include "DifficultyFactor.h"

//===== CONSTRUCTOR =====
DifficultyFactor::DifficultyFactor(double weight, int difficulty)
{
	_weight = weight;
	_currentDifficulty = getDifficultyLevel(difficulty);
}

//===== DESTRUCTOR =====
DifficultyFactor::~DifficultyFactor(void)
{

}

//===== FUNCTIONS =====

/*!
    @function getDifficultyLevel
    @param		difficulty: int
				new difficulty level to determine factor contribution
    @result		find difficulty level by multiplying by weight
*/
int DifficultyFactor::getDifficultyLevel(int difficulty)
{
	int tempDifficulty = int(_weight * difficulty);

	if ( tempDifficulty <= 0 )
	{
		return 1;
	}

	return tempDifficulty;
}

/*!
    @function updateDifficulty
    @param		difficulty: int
				new difficulty level to determine factor contribution, always > 0
    @result		true - difficulty is updated
    			false - difficulty remains the same, stop update function
*/
bool DifficultyFactor::updateDifficulty(int difficulty)
{
	if( difficulty <= 0 )
	{
		return false;
	}

	int tempDifficulty = getDifficultyLevel(difficulty);

	if( tempDifficulty == _currentDifficulty )
	{
		return false;
	}

	_currentDifficulty = tempDifficulty;
	return true;
}
